package com.jt.www.admin.user.controller;

import com.github.pagehelper.PageInfo;
import com.jt.www.admin.user.service.BranchOfficeService;
import com.jt.www.model.param.branchOffice.BranchOfficeParam;
import com.jt.www.model.reps.GenericDataResponse;
import com.jt.www.model.reps.GenericListResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "分支机构", description = "分支机构")
@RestController
@RequestMapping(value = "/pro/v1/branch-ffice")
public class BranchOfficeController {
    @Autowired
    private BranchOfficeService officeService;

    @ApiOperation(value = "省级行政区参数列表", httpMethod = "GET")
    @GetMapping(value = "/provinces", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseEntity getProvinces() {
        List<String> provinces = officeService.getProvinces();
        return GenericDataResponse.okWithData(provinces);
    }

    @ApiOperation(value = "分支机构列表", httpMethod = "POST")
    @PostMapping(value = "/offices", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseEntity getList(@RequestBody BranchOfficeParam param) {
        PageInfo pageInfo = officeService.getList(param);
        return GenericListResponse.listAndCount(pageInfo.getList(), pageInfo.getTotal());
    }
}
